<?php
/**
 * 
 * ClientEngage: ClientEngage Visitor Voice (http://www.clientengage.com)
 * Copyright 2012, ClientEngage (http://www.clientengage.com)
 *
 * You must have purchased a valid license from CodeCanyon in order to have 
 * the permission to use this file.
 * 
 * You may only use this file according to the respective licensing terms 
 * you agreed to when purchasing this item on CodeCanyon.
 * 
 * 
 * 
 *
 * @author          ClientEngage <contact@clientengage.com>
 * @copyright       Copyright 2013, ClientEngage (http://www.clientengage.com)
 * @link            http://www.clientengage.com ClientEngage
 * @since           ClientEngage - Visitor Voice v 1.0
 * 
 */
?>
<?php
echo $this->Html->scriptBlock('
$(function() {
    $(".chk_selectall").on("click", function() {
        $(".chk_del").prop("checked", this.checked);
    });
    
    $(".chk_del").on("change", function() {
        $(".btn_deleteall").prop("disabled", !($(".chk_del:checked").length > 0));
    });
    
    $(".chk_selectall").on("change", function() {
            $(".btn_deleteall").prop("disabled", !this.checked);
    });
});
');
?>
<div class="visitorvoices index row">
    <div class="span12">
        <div class="btn-group pull-right" style="margin-left: 15px">
            <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">
                <?php echo __('Export Responses'); ?>
                <span class="caret"></span>
            </a>
            <ul class="dropdown-menu">
                <li><?php echo $this->Html->link('<i class="ico-page_white_excel"></i> ' . __('Export to Excel'), array('controller' => 'visitorvoices', 'action' => 'export', $visitorform['Visitorform']['id'], 'xls'), array('class' => '', 'escape' => false, 'target' => 'blank')); ?></li>
                <li><?php echo $this->Html->link('<i class="ico-page_white"></i> ' . __('Export to CSV'), array('controller' => 'visitorvoices', 'action' => 'export', $visitorform['Visitorform']['id'], 'csv'), array('class' => '', 'escape' => false, 'target' => 'blank')); ?></li>
            </ul>
        </div>
        <div class="btn-group pull-right">
            <?php
            echo $this->Html->link('<i class="ico-chart_curve"></i> ' . __('View Statistics'), array('action' => 'statistics', $visitorform['Visitorform']['id']), array('class' => 'btn btn-primary', 'escape' => false));
            echo $this->Form->postLink('<i class="ico-cancel"></i> ' . __('Delete All'), array('action' => 'deleteall', $visitorform['Visitorform']['id']), array('class' => 'btn btn-danger', 'title' => __('Delete'), 'escape' => false), __('Are you sure you want to delete all responses of this visitor form?'));
            ?>
        </div> 
        <h2><?php echo $this->Html->link($visitorform['Visitorform']['title'], array('controller' => 'visitorforms', 'action' => 'view', $visitorform['Visitorform']['id'])) . ': ' . __('Visitorvoices'); ?> <small><?php echo String::insert(__n(':count Response', ':count Responses', $visitorform['Visitorform']['visitorvoice_count']), array('count' => $visitorform['Visitorform']['visitorvoice_count'])); ?></small></h2>
        <?php if ($visitorform['Visitorform']['visitorvoice_count']): ?>
            <?php echo $this->Form->create('Meta', array('url' => array('controller' => 'visitorvoices', 'action' => 'deleteselected'))); ?>
            <?php echo $this->Form->input('visitorform_id', array('type' => 'hidden', 'value' => $visitorform['Visitorform']['id'])); ?>
            <div id="doublescroll">
                <table class="table table-striped table-condensed response_table" style="white-space:nowrap;">
                    <tr class="response_table_header">
                        <?php foreach ($viewData['fields'] as $key => $field): ?>
                            <?php if ($key != 'ID'): ?>
                                <th<?php echo ((isset($field['type']) && in_array($field['type'], array('checkboxmultiple', 'selectmultiple'))) ? ' class="narrow"' : ''); ?>><?php echo $field['title']; ?></th>
                            <?php else: ?>
                                <th>
                            <div class="btn-group">
                                <span class="btn btn-mini"><?php echo $this->Form->checkbox('chkAll', array('div' => false, 'class' => 'chk_selectall', 'style' => 'margin-top: -2px;')); ?></span>
                                <?php echo $this->Form->Button(__('Delete'), array('class' => 'btn btn-mini btn-danger btn_deleteall', 'disabled' => true, 'onclick' => 'if (!confirm(\'' . __('Are you sure you wish to delete all selected visitor voices?') . '\')) { return false; } ')); ?>
                            </div>        
                            </th>
                        <?php endif; ?>
                    <?php endforeach; ?>
                    </tr>
                    <?php foreach ($viewData['data'] as $data): ?>
                        <tr>
                            <?php foreach ($data as $id => $point): ?>
                                <?php if ($id == 'ID'): ?>
                                    <td>
                                        <div class="btn-group pull-right">
                                            <span class="btn btn-mini"><?php echo $this->Form->checkbox('del.', array('div' => false, 'class' => 'chk_del', 'value' => $point, 'style' => 'margin-top: -2px;', 'hiddenField' => false)); ?></span>
                                            <?php echo $this->Html->link('<i class="ico-magnifier"></i>', array('action' => 'view', $point), array('class' => 'btn btn-mini', 'title' => __('View'), 'escape' => false)); ?>
                                        </div>
                                    </td>
                                <?php elseif ($id == 'UserAgent'): ?>
                                    <td class="<?php echo $point === null ? 'nullcell' : ''; ?>"><?php echo $this->Layout->renderUserAgent($point, false); ?></td>
                                <?php else: ?>
                                    <td class="<?php echo $point === null ? 'nullcell' : ''; ?>"><?php echo $point; ?></td>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        </tr>
                    <?php endforeach; ?>
                </table>
            </div>
            <?php echo $this->Form->end(); ?>
            <br />
            <?php
            echo $this->element('common/defaultpagination');
            ?>	
        <?php else: ?>
            <div class="well">
                <?php echo __('No responses available'); ?>
            </div>
        <?php endif; ?>
    </div>
</div>

<?php ?>

<style type="text/css">
    #doublescroll { overflow: auto; overflow-y: hidden; border: 1px solid #ccc }
</style>
<script type="text/javascript">
    function DoubleScroll(element) {
        var scrollbar = document.createElement('div');
        scrollbar.appendChild(document.createElement('div'));
        scrollbar.style.overflow = 'auto';
        scrollbar.style.overflowY = 'hidden';
        scrollbar.firstChild.style.width = element.scrollWidth + 'px';
        scrollbar.firstChild.style.paddingTop = '1px';
        scrollbar.firstChild.appendChild(document.createTextNode('\xA0'));
        scrollbar.onscroll = function() {
            element.scrollLeft = scrollbar.scrollLeft;
        };
        element.onscroll = function() {
            scrollbar.scrollLeft = element.scrollLeft;
        };
        element.parentNode.insertBefore(scrollbar, element);
    }
    $(function() {
        DoubleScroll(document.getElementById('doublescroll'));
    });
</script>